<?php include("IncAuthentication.php")?>

	<SCRIPT type="text/javascript" src="js/jquery.validate.js"></SCRIPT>   
   	<SCRIPT type="text/javascript" src="js/jquery.kent.js"></SCRIPT>
    
   	<SCRIPT type="text/javascript">
		
		$(document).ready(function()
		{
			$("#sendF").validate(
			{
				rules: 
				{
					txtEmail: {email:true},
				}
			});
		});
		</SCRIPT>   
<?php
	include("ProductDetail.php");
	mysql_query("SET character_set_results=utf8");
	if(isset($_POST['btnSend']))
	{
		$MaKH = $_SESSION['KhachHang']['MaKH'];
		$HoTen = $_POST['txtHoTen'];
		$Email = $_POST['txtEmail'];
		$GhiChu = $_POST['txtGhiChu'];
		$NgayGui = date('Y-m-d');
		
		$sql = "INSERT INTO BanBe(MaHH, MaKH, HoTen, Email, NgayGui, GhiChu) 
				VALUES('$MaHH', '$MaKH', '$HoTen', '$Email', '$NgayGui', '$GhiChu')";
		if(mysql_query($sql))
		{
			include("gmail/mailer.php");
		
			$mail->From = $_SESSION['KhachHang']['Email'];
			$mail->FromName = $_SESSION['KhachHang']['HoTen'];
			$mail->AddAddress($Email, $HoTen);
			$mail->Subject = "$HoTen sent the info of $row[TenHH] to you !";
			$ProductUrl = "http://$_SERVER[HTTP_HOST]/Webfood/index.php?p=ProductDetail&MaHH=$MaHH";
			$mail->Body = $GhiChu . "<p><p>Click to <a href='$ProductUrl'>view</a> product detail !";
			
			if(!$mail->Send())
			{
				$ThongBaoLoi = "Unenabled to send email !";
			}
			else
			{
				$ThongBaoLoi = "The product was sent to your friend !";
			}
		}
		else
		{
			$ThongBaoLoi = "Unenabled to save the email !";
		}
	}
?>
<form method="post" id="sendF">
<table border="0" align="left" cellpadding="5" cellspacing="0" style="text-align:left">
  <tr>
    <td>Your Name</td>
    <td>:</td>
    <td>&nbsp;<?php echo $_SESSION['KhachHang']['HoTen'] ?></td>
  </tr>
  <tr>
    <td>Enclosed Product</td>
    <td>:</td>
    <td>
		<?php echo $row['TenHH']?>
        <input name="MaHH" type="hidden" id="MaHH" value="<?php echo $MaHH?>" />
    </td>
  </tr>
  <tr>
    <td>Recipient's Name</td>
    <td>:</td>
    <td><input name="txtHoTen" type="text" id="txtHoTen"  /></td>
  </tr>
  <tr>
    <td>Recipient's Email</td>
    <td>:</td>
    <td><input name="txtEmail" type="text" id="txtEmail"  /></td>
  </tr>
  <tr>
    <td>Comments</td>
    <td>:</td>
    <td><textarea name="txtGhiChu" cols="40" rows="5" id="txtGhiChu"></textarea></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type="submit" name="btnSend" id="btnSend" value="Send" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><?php echo $ThongBaoLoi ?>&nbsp;</td>
  </tr>
</table>
</form>